package com.example.dp.jiemian.bt1;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;

import com.example.dp.jiemian.R;
import com.example.dp.jiemian.bt1.bean.ViewPagerIndicator;
import com.example.dp.jiemian.bt1.bean.ViewSimpleFragment;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class bt1 extends FragmentActivity {

    private ViewPager mViewPager;
    //ads
    private ViewPagerIndicator mIndicator;

    private List<String> mTitles = Arrays.asList("短信1","收藏2","推荐3","短信4","收藏5","推荐6","短信7","收藏8","推荐9");
    private List<ViewSimpleFragment> mContents = new ArrayList<ViewSimpleFragment>();
    private FragmentPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bt1);

        initViews();//绑定控件
        initDatas();//根据名字加入管理

        mIndicator.setVisibleTabCount(4);//设置可见的tab数量
        mIndicator.setTabItemTitles(mTitles);//输入tab数量及相关属性

        mViewPager.setAdapter(mAdapter);//设置Fragment设配器
        mIndicator.setViewPager(mViewPager,0);//fragment与tab结合寄来管理
    }

    private void initDatas() {
        for (String title:mTitles){
            ViewSimpleFragment fragment = ViewSimpleFragment.newInstance(title);
            mContents.add(fragment);
        }
        mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return mContents.get(position);
            }

            @Override
            public int getCount() {
                return mContents.size();
            }
        };
    }

    private void initViews() {
        //ADS
        mViewPager = findViewById(R.id.viewpager);
        mIndicator = findViewById(R.id.indicator);
    }

}
